package gr.uoa.di.thanos.botcraft.gui;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import gr.uoa.di.thanos.botcraft.Configuration;

public class About extends JFrame implements Runnable {
	private static final long serialVersionUID = 1L;

	private static final Logger LOGGER = Logger.getLogger(About.class.getName());
	
	private final JEditorPane about;
	
	public static void main(final String[] arguments) {
		try {
			final About about = new About(new Configuration());
			about.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			SwingUtilities.invokeLater(about);
		} catch (final IOException e) {
			LOGGER.log(Level.SEVERE, "Error loading about", e);
			JOptionPane.showMessageDialog(null, new Configuration().getResourceBundle().getString("errorLoadingAbout"), e.getClass().getName(), JOptionPane.ERROR_MESSAGE);
		}
	}

	public About(final Configuration configuration) throws IOException {
		setTitle(configuration.getResourceBundle().getString("about"));
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		final Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
		final Dimension size = new Dimension(Double.valueOf(bounds.getWidth()).intValue(), Double.valueOf(bounds.getHeight()).intValue());
		setMaximumSize(size);
		setPreferredSize(size);
		about = new JEditorPane(About.class.getResource(configuration.getResourceBundle().getString("_about")));
		about.setEditable(false);
		add(new JScrollPane(about, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		pack();
	}
	
	@Override
	public void run() {
		setVisible(true);
		about.requestFocusInWindow();
	}
}
